/**
 * 项目记录表js
 */

$(function () {
    vm.getHospitals();
    vm.getResolvingStatus();
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url: '../../project/record/list?_' + $.now(),
		height: $(window).height()-56,
		queryParams: function(params){
			params.name = vm.keyword;
			return params;
		},
		columns: [
			{checkbox: true},
            {field : "hospitalName", title : "医院", width : "200px"},
            {field : "department", title : "科室", width : "100px"},
            {field : "projectName", title : "项目名称", width : "200px"},
            {field : "contact", title : "联系人", width : "100px"},
            {field : "contactNumber", title : "联系电话", width : "100px"},
            {field : "operationMaintenancePerson", title : "运维人员", width : "100px"},
            {field : "resolvingStatusName", title : "解决状态", width : "100px"},
            {field : "resolvingProgress", title : "解决进展", width : "100px"},
            {field : "projectOverview", title : "项目概述", width : "100px"},
            {field : "gmtCreate", title : "创建时间", width : "200px"},
            {title : "操作", formatter : function(value, row, index) {
                    var _html = '';
                    if (hasPermission('project:record:edit')) {
                        _html += '<a href="javascript:;" onclick="vm.edit(\''+row.id+'\')" title="编辑"><i class="fa fa-pencil"></i></a>';
                    }
                    if (hasPermission('project:record:remove')) {
                        _html += '<a href="javascript:;" onclick="vm.remove(false,\''+row.id+'\')" title="删除"><i class="fa fa-trash-o"></i></a>';
                    }
                    _html += '<a href="javascript:;" onclick="vm.downloadAttachment(\'' + row.attachment + '\')" title="下载附件"><i class="fa fa-download"></i></a>';
                    return _html;
                }
            }
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
        keyword: "",
        keyword1: "",
        keyword2: "",
        optionsHospital: [],
        optionsResolvingStatus: [],
	},
	methods : {
		load: function(type) {
            vm.keyword = vm.keyword2;
            if (type == 1){
                vm.keyword = vm.keyword1;
            }
		    getGrid();
			$('#dataGrid').bootstrapTable('refresh');
		},
		save: function() {
			dialogOpen({
				title: '新增项目记录', url: 'base/record/add.html?_' + $.now(),
				width: '450px',
                height: '620px',
                scroll: true,
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit: function(id) {
            dialogOpen({
                title: '编辑项目记录',
                url: 'base/record/edit.html?_' + $.now(),
                width: '450px',
                height: '620px',
                scroll: true,
                success: function(iframeId){
                    top.frames[iframeId].vm.projectRecord.id = id;
                    top.frames[iframeId].vm.setForm();
                },
                yes: function(iframeId){
                    top.frames[iframeId].vm.acceptClick();
                }
            });
        },
        remove: function(batch, id) {
            var ids = [];
            if (batch) {
                var ck = $('#dataGrid').bootstrapTable('getSelections');
                if (!checkedArray(ck)) {
                    return false;
                }
                $.each(ck, function(idx, item){
                    ids[idx] = item.id;
                });
            } else {
                ids.push(id);
            }
            $.RemoveForm({
                url: '../../project/record/remove?_' + $.now(),
                param: ids,
                success: function(data) {
                    vm.load();
                }
            });
        },
        downloadAttachment: function (attachment) {
            $.DownLoanForm({
                param: attachment,
            });
        },
        getHospitals: function () {
            $.getJSON("/sys/macro/value?_" + $.now() + "&value=客户", function (r) {
                vm.optionsHospital = r;
            });
        },
        getResolvingStatus: function () {
            $.getJSON("/sys/macro/value?_" + $.now() + "&value=解决状态", function (r) {
                vm.optionsResolvingStatus = r;
            });
        },
	}
})